<?php

use App\Models\Details;
use App\Models\Users;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\GoodsController;
use App\Http\Controllers\AddressController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\MyController;
use App\Http\Controllers\WechatController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//授权
Route::get('/{parent?}',[LoginController::class, 'login'])->middleware('Auth.WeChat');


Route::group([
    'prefix' => 'wechat',
], function ($router) {
    //支付回调
    Route::any('payCallback',[WechatController::class, 'payCallback']);
    //退款回调
//    Route::any('refundCallback',[WechatController::class, 'refundCallback']);

    Route::any('serve', [WechatController::class, 'serve']);
    //自定义菜单
    //
    //Route::any('menu',[WechatController::class, 'wechatMenu']);
});

Route::group(['prefix' => 'auth'], function () {

    Route::post('certification', [LoginController::class, 'certification']);

});

//商品信息
Route::group(['prefix' => 'goods'], function () {
    //商品列表
    Route::get('list', [GoodsController::class, 'index'])->middleware('check.view.session');
    //商品详情
    Route::get('detail', [GoodsController::class, 'detail'])->middleware('check.view.session');

});

//收货地址
Route::group(['prefix' => 'user'], function () {
    //我的
    Route::get('my', [MyController::class, 'index'])->middleware('check.view.session');
    //收货地址列表
    Route::get('address', [AddressController::class, 'index'])->middleware('check.view.session');
    //添加收货地址页面
    Route::get('addressAdd', [AddressController::class, 'store'])->middleware('check.view.session');

    //删除收货地址
    Route::delete('deleteAddress/{id}', [AddressController::class, 'delete'])->middleware('check.ajax.session');
    //修改收货地址
    Route::post('createAddress', [AddressController::class, 'createAddress'])->middleware('check.ajax.session');
    //修改收货地址
    Route::post('saveAddress', [AddressController::class, 'saveAddress'])->middleware('check.ajax.session');
});

//订单
Route::group(['prefix' => 'order'], function () {
    //提交订单页面
    Route::get('submit', [OrderController::class, 'store'])->middleware('check.view.session');
    //提交订单
    Route::post('subOrder', [OrderController::class, 'subOrder'])->middleware('check.ajax.session');
    //我的订单去支付
    Route::post('goPay', [OrderController::class, 'goPay'])->middleware('check.ajax.session');
    //确认收货
    Route::post('confirm/{orderSn}', [OrderController::class, 'confirmOrder'])->middleware('check.ajax.session');
    //取消订单
    Route::post('cancel/{orderSn}', [OrderController::class, 'cancelOrder'])->middleware('check.ajax.session');

});

//我的
Route::group(['prefix' => 'my'], function () {
    //我的订单
    Route::get('order', [MyController::class, 'myOrder'])->middleware('check.view.session');
    //我的余额
    Route::get('money', [MyController::class, 'myMoney'])->middleware('check.view.session');
    //实名认证
    Route::get('authentication', [MyController::class, 'authentication'])->middleware('check.view.session');
    //我的邀请人
    Route::get('invitation', [MyController::class, 'myInvitation'])->middleware('check.view.session');
    //检测是否有分享权限
    Route::post('share', [MyController::class, 'share'])->middleware('check.ajax.session');
    //修改用户信息
    Route::post('saveInfo', [MyController::class, 'saveUserInfo'])->middleware('check.ajax.session');

});

